<template>
  <el-container class="home">
    <el-header>
      <div class="logo">
        <img src="../assets/logo.png" />
        <h1>电商后台管理系统</h1>
      </div>
      <el-button type="info" @click="signout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :style="{width:isCollapse?'64px':'200px'}">
        <div class="toggle-button" @click="togglebutton">|||</div>
        <el-menu
          :default-active="activePath"
          background-color="#333744"
          active-text-color="#409EFF"
          class="el-menu-vertical-demo"
          :collapse-transition="false"
          :collapse="isCollapse"
          unique-opened
          router
        >
          <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
            <template slot="title">
              <i :class="iconlist[item.id]"></i>
              <span slot="title" class="title">{{item.authName}}</span>
            </template>

            <el-menu-item
              :index="subitem.path"
              v-for="subitem in item.children"
              :key="subitem.id"
              @click="sivepath(subitem.path)"
            >
                <template>
                <i class="el-icon-menu"></i>
                <span slot="title">{{subitem.authName}}</span>
                </template>

            
            
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "home",
  data() {
    return {
      isCollapse: false,
      menulist: [],
      iconlist:{
        '125':"iconfont icon-users",
        '103':"iconfont icon-3702mima",
        '101':"iconfont icon-shangpin",
        '102':"iconfont icon-danju",
        '145':"iconfont icon-tijikongjian"
      },
      activePath:""
    };
  },
  methods: {
    togglebutton() {
      this.isCollapse = !this.isCollapse;
    },
    async getMenu() {
      const { data: res } = await this.$http.get("menus");

      this.menulist = res.data;
      //console.log(this.menulist);
    },
    signout() {
      window.sessionStorage.clear();
      this.$router.push({ path: "/login" });
    },
    sivepath(path) {
      window.sessionStorage.setItem('path',path);
      this.activePath =path;
      

    }
  },
  created() {
    this.getMenu();
    this.activePath = window.sessionStorage.getItem('path');
  }
};
</script>

<style lang="scss"  scoped>
.home {
  height: 100%;
}
.el-header {
  background: #373d41;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.logo {
  vertical-align: top;
}
.logo img {
  width: 60px;
  display: inline-block;
  vertical-align: top;
  margin-right: 10px;
}
.logo h1 {
  line-height: 60px;
  display: inline-block;
  vertical-align: top;
  color: #fff;
}

.el-aside {
  background: rgb(51, 55, 68);
  color: #fff;
}

.el-menu {
  background-color: rgb(51, 55, 68);
  color: #fff;
  border-right: 1px solid rgb(51, 55, 68);
  .title {
    color: #fff;
  }
  .el-menu-item {
    color: #fff;
  }
}

.toggle-button {
  line-height: 30px;
  background: #4a5064;
  font-size: 14px;
  text-align: center;
  cursor: pointer;
}
</style>